package com.sendpo.zjx.sendpo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.sendpo.zjx.sendpo.R;
import com.sendpo.zjx.sendpo.utils.Tools;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by zjx on 2018
 */

public class CreateBusStoreActivity extends AppCompatActivity {
    public static final int REQUEST_Address = 104;
    public static final int REQUEST_SUBMIT = 105;
    public static final int REQUEST_TYPE = 103;
    @BindView(R.id.backbt)
    RelativeLayout backbt;
    @BindView(R.id.head)
    RelativeLayout head;
    @BindView(R.id.storename_tv)
    TextView storenameTv;
    @BindView(R.id.realname)
    EditText realname;
    @BindView(R.id.storeaddress_tv)
    TextView storeaddressTv;
    @BindView(R.id.address_right)
    ImageView addressRight;

    @BindView(R.id.storeaddress_bt)
    RelativeLayout storeaddressBt;
    @BindView(R.id.storephone_tv)
    TextView storephoneTv;
    @BindView(R.id.storephone_edit)
    EditText storephoneEdit;
    @BindView(R.id.jinying_tv)
    TextView jinyingTv;
    @BindView(R.id.type)
    TextView type;
    @BindView(R.id.jinying_bt)
    RelativeLayout jinyingBt;
    @BindView(R.id.ready_bt)
    Button readyBt;
    private String address = "";
    private String mCurrentLat = "";
    private String mCurrentLon = "";
    private String province = "";
    private String area = "";
    private String city = "";
    @BindView(value = R.id.address)
    public TextView address_tv;
    private String store_type="";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_createbusstore);
        Tools.initStatus(this, R.color.black);
        ButterKnife.bind(this);
        initComponent();
    }

    private void initComponent() {

    }

    @OnClick(value = {R.id.backbt,R.id.storeaddress_bt,R.id.jinying_bt,R.id.ready_bt})
    public void onMyClick(View view) {
        switch (view.getId()) {
            case R.id.backbt:
                finish();
                break;
            case R.id.storeaddress_bt:
                  startActivityForResult(new Intent(this, LocationMapActivity.class), REQUEST_Address);
        break;
            case R.id.jinying_bt:
                startActivityForResult(new Intent(this, StoreCategoryActivity.class), REQUEST_TYPE);
                break;

            case R.id.ready_bt:
                if (TextUtils.isEmpty(this.realname.getText().toString().trim()))
                {
                    Toast.makeText(getApplicationContext(), "店铺名不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (TextUtils.isEmpty(this.province))
                {
                    Toast.makeText(getApplicationContext(), "尚未选择店铺地址", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (TextUtils.isEmpty(this.storephoneEdit.getText().toString().trim()))
                {
                    Toast.makeText(getApplicationContext(), "手机号不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (this.store_type.equals(""))
                {
                    Toast.makeText(getApplicationContext(), "没有选择店铺经营类型", Toast.LENGTH_SHORT).show();
                    return;
                }
                Intent intent=new Intent(this, BussStoreShenfenRenzhenActivity.class);
                intent.putExtra("merchantsName", "" + this.realname.getText().toString().trim());
                intent.putExtra("merchantsProvince", "" + this.province);
                intent.putExtra("merchantsCity", "" + this.city);
                intent.putExtra("merchantsArea", "" + this.area);
                intent.putExtra("merchantsAddress", "" + this.address);
                intent.putExtra("merchantsPhone", "" + this.storephoneEdit.getText().toString().trim());
                int type=0;
                if(store_type.equals("商品")){
                    type=0;
                  }else if(store_type.equals("餐饮")){
                    type=1;
                }else if(store_type.equals("影视")){
                    type=2;
                }else if(store_type.equals("健康")){
                    type=3;
                }else if(store_type.equals("其他")){
                    type=4;
                }
                intent.putExtra("merchantsIndustry", "" +type);
                intent.putExtra("merchantsLongitude", "" + this.mCurrentLon);
                intent.putExtra("merchantsLatitude", "" + this.mCurrentLat);
                startActivityForResult(intent, REQUEST_SUBMIT);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
                 if(resultCode!=RESULT_OK){
                     return;
                 }

                 switch (requestCode){
                     case REQUEST_Address:
                     this.mCurrentLat = data.getStringExtra("mCurrentLat");
                     this.mCurrentLon = data.getStringExtra("mCurrentLon");
                     this.province = data.getStringExtra("province");
                     this.city = data.getStringExtra("city");
                     this.area = data.getStringExtra("area");
                     this.address = data.getStringExtra("address");
                     this.address_tv.setText("" + this.province + this.city + this.area + this.address);
                 break;

                     case REQUEST_TYPE:
                         if(data==null){
                             return;
                         }
                         store_type =data.getStringExtra("type");
                         this.type.setText(""+store_type);
                         break;

                     case REQUEST_SUBMIT:
                         finish();
                         break;

                 }

    }
}
